home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ModemStub.c
-
- Contains: xxx put contents here xxx
-
- Version: xxx put version here xxx
-
- Copyright: © 1998-1999 by Apple Computer, Inc., all rights reserved.
-
- File Ownership:
-
- DRI: xxx put dri here xxx
-
- Other Contact: xxx put other contact here xxx
-
- Technology: xxx put technology here xxx
-
- */
-
- #include <Errors.h>
-
- #include "Modem.h"
- #include "ModemStub.h"
- #include "ModemDriver.h"
- #include "ShimSerialStub.h"
- #include "ShimSerialHAL.h"
- #include "ModemVersion.h"
-
- //------------------------------------------------------
- //
- // Globals
- //
- //------------------------------------------------------
-
- ShimSerialGlobals* gGlobals;
-
- //------------------------------------------------------
- //
- // This is the driver description structure that the expert looks for first.
- // If it's here, the information within is used to match the driver
- // to the device whose descriptor was passed to the expert.
- // Information in this block is also used by the expert when an
- // entry is created in the Name Registry.
- //
- //------------------------------------------------------
-
- USBDriverDescription TheUSBDriverDescription =
- {
- // Signature info
- kTheUSBDriverDescriptionSignature,
- kInitialUSBDriverDescriptor,
-
- // Device Info
- kUSBVendor, // vendor ID
- kUSBProduct, // product ID
- 0, // version of product = not device specific
- 0, // protocol = not device specific
-
- // Interface Info
- 0, // Configuration Value (doesn't matter)
- 0, // Interface Number
- kUSBCommClass, // Interface Class
- 2, // Interface SubClass (Abstract Control Model)
- 1, // Interface Protocol (V.25ter)
-
- // Driver Info
- kModemName, // Driver name for Name Registry
- kUSBCommClass, // Device Class
- 0, // Device Subclass
- kVMajor, // version of driver (see ModemVersion.h)
- kVMinor,
- kVStage,
- kVRelease,
-
- // Driver Loading Info
- // kUSBDoNotMatchGenericDevice // Flags
- 0
- };
-
- USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
- {
- kClassDriverPluginVersion, // Version of this structure
- modemDriverValidateHW, // Hardware Validation Procedure
- modemDriverInitialize, // Initialization Procedure
- modemDriverInitInterface, // Interface Initialization Procedure
- modemDriverFinalize, // Finalization Procedure
- modemDriverNotifyProc,
- };
-
- CFragConnectionID ConnID; // Need to remember this
-
- /***********************************************************************************/
- // Function: modemDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
- // Description: Called upon load by Expert
- //
- // Input: Device reference, Device descriptor
- // Output: noErr
- /***********************************************************************************/
-
- static OSStatus modemDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
- {
- #pragma unused (device, desc)
-
- TraceMessage(0,kCRMName"- Entering modemDriverValidateHW");
-
- return noErr;
- }
-
- /***********************************************************************************/
- // Function: OSStatus modemDriverInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc,
- // UInt32 busPowerAvailable)
- // Description: Called upon load by Expert
- //
- // Input: Device reference, Device descriptor, bus power available
- // Output: result
- /***********************************************************************************/
-
- static OSStatus modemDriverInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable)
- {
- #pragma unused (busPowerAvailable)
-
- OSStatus err;
-
- TraceMessage(0,kCRMName"- Entering modemDriverInitialize");
-
- gGlobals = (ShimSerialGlobals*)PoolAllocateResident(sizeof(ShimSerialGlobals),true);
- if (gGlobals == NULL)
- goto bail;
-
- USBExpertStatus(0, kCRMName"- Modem driver loading as Class - "kVers2Long Bugon, 0);
-
- err = modemDriverEntry(device, pDesc);
-
- if (err != noErr)
- {
- StatusMessage(0, kCRMName"- Configuration failed", err);
- goto bail;
- } else {
- // Install Device Control Entry for both the ".In" and ".Out functions that are
- // requied for a serial driver which is what we are.
- if (noErr != InstallShimDrvr(ConnID))
- {
- StatusMessage(0, kCRMName" - Can't install DCEs!", 0);
- goto bail;
- }
- }
-
- return noErr;
-
- bail:
- if (gGlobals)
- PoolDeallocate(gGlobals);
- gGlobals = NULL;
-
- return openErr;
- }
-
- /***********************************************************************************/
- // Function: modemDriverInitInterface(UInt32 interfaceNum, USBInterfaceDescriptor *interfaceDesc,
- // USBDeviceDescriptor *deviceDesc, USBDeviceRef device)
- // Description: Called to initialize driver for an individual interface -
- // either by expert or internally by driver
- //
- // Input: Interface number, Interface descriptor, Device Descriptor, Device Reference
- // Output: result
- /***********************************************************************************/
-
- static OSStatus modemDriverInitInterface(UInt32 interfaceNum, USBInterfaceDescriptor *interfaceDesc, USBDeviceDescriptor *deviceDesc, USBDeviceRef device)
- {
- #pragma unused (interfaceNum, interfaceDesc)
-
- OSStatus err;
-
- TraceMessage(0,kCRMName"- Entering modemDriverInitInterface");
-
- if (gGlobals == NULL)
- gGlobals = (ShimSerialGlobals*)PoolAllocateResident(sizeof(ShimSerialGlobals),true);
-
- if (gGlobals == NULL)
- goto bail;
-
- USBExpertStatus(0, kCRMName"- Modem driver loading as Interface "kVers2Long Bugon, 0);
-
- err = modemDriverEntry(device, deviceDesc);
-
- if (err != noErr)
- {
- StatusMessage(0, kCRMName"- Configuration failed", err);
- goto bail;
- } else {
- // Install Device Control Entry for both the ".In" and ".Out functions that are
- // requied for a serial driver which is what we are.
- if (noErr != InstallShimDrvr(ConnID))
- {
- StatusMessage(0, kCRMName"- Can't install DCEs!", 0);
- goto bail;
- }
- }
-
- return noErr;
-
- bail:
- if (gGlobals)
- PoolDeallocate(gGlobals);
- gGlobals = NULL;
-
- return openErr;
- }
-
- /***********************************************************************************/
- // Function: modemDriverFinalize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc)
- // Description: Called by Expert when driver is being shut down
- //
- // Input: Device reference, Device descriptor
- // Output: noErr
- /***********************************************************************************/
-
- static OSStatus modemDriverFinalize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc)
- {
- #pragma unused (device, pDesc)
-
- TraceMessage(0,kCRMName"- Entering modemDriverFinalize");
-
- if (gGlobals)
- {
- /* This is done here just as a safeguard because it should have been done in the notify proc */
- // KillUSBIO();
- ResetDevice();
- RemoveShimDrvr(true); // force close - let the shim handle it
- PoolDeallocate(gGlobals);
- gGlobals = NULL;
- }
-
- return noErr;
- }
-
- /***********************************************************************************/
- // Function: ExpertEntryProc(ExpertNotificationProcPtr pExpertNotify)
- // Description:
- //
- // Input: Notification proc pointer
- // Output: noErr
- /***********************************************************************************/
-
- static OSStatus ExpertEntryProc(ExpertNotificationProcPtr pExpertNotify)
- {
- #pragma unused (pExpertNotify)
-
- TraceMessage(0,kCRMName"- Entering ExpertEntryProc");
-
- return noErr;
- }
-
- /***********************************************************************************/
- // Function: modemDriverNotifyProc(UInt32 notification, void *pointer)
- // Description:
- //
- // Input: Notification and pointer
- // Output: result
- /***********************************************************************************/
-
- static OSStatus modemDriverNotifyProc(UInt32 notification, void *pointer, UInt32 refcon)
- {
- #pragma unused (pointer, refcon)
-
- TraceMessage(0,kCRMName"- Entering modemDriverNotifyProc");
- StatusMessage(0, kCRMName"- Driver Notification = ", notification);
-
- if (notification == kNotifyRemoveDevice)
- {
- if (gGlobals->ShimRef != kInvalidRef)
- {
- KillUSBIO();
- RemoveShimDrvr(true); // force close - let the shim handle it
-
- if (gGlobals)
- {
- PoolDeallocate(gGlobals);
- gGlobals = NULL;
- }
- }
- }
-
- return noErr;
- }
-
- /***********************************************************************************/
- // Function: InitDriver(CFragInitBlock *init)
- // Description: This routine saves our connection id
- //
- // Input: init (unused)
- // Output: noErr
- /***********************************************************************************/
-
- OSErr InitDriver(CFragInitBlock *init)
- {
- OSErr err = noErr;
-
- TraceMessage(0, kCRMName"- Entering initDriver");
-
- ConnID = init->connectionID;
-
- return err;
- }